#pragma once


#include <string>
#include <functional>
#include "log.hpp"

using namespace Logspace;

class Connection;
using func_t = std::function<void(std::shared_ptr<Connection>)>;

class Connection
{
public:
    Connection(int fd , func_t recv , func_t sender , func_t exception)
    :_fd(fd) , 
    _Recv(recv) , _Sender(sender) , _Exception(exception)
    {
    }

    std::string& Get_Inbuffer()
    {
        return _inbuffer;
    }
    std::string& Get_Outbuffer()
    {
        return _outbuffer;
    }

    void Add_In(const std::string& mes)
    {
        _inbuffer += mes;
    }
    void Add_Out(const std::string& mes)
    {
        _outbuffer += mes;
    }

    int Get_fd()
    {
        return _fd;
    }
private:
    int _fd;                 // 对应的文件描述符
    std::string _inbuffer ;  // 输入缓冲区
    std::string _outbuffer;  // 输出缓冲区
public:
    func_t _Recv;             // 处理接收的逻辑
    func_t _Sender;           // 处理发送的逻辑
    func_t _Exception;        // 处理出现异常时的逻辑
};